<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" value="点击" id="btn">
    <!-- 题目要求:请自定义一个注册事件的兼容函数，要求兼容三种注册事件方法。 -->
    <script>
        // 获取元素
        var btn = document.getElementById('btn');

        // 触发事件
        addEvent(btn, 'click', function() {
            alert(1)
        });


        // 注册事件兼容写法
        function addEvent(ele, type, fn) {
            if (ele.addeventListerent) {
                ele.addeventListerent(type, fn)
            } else if (ele.attachEvent) {
                ele.attachEvent('on' + type, fn)
            } else {
                ele['on' + type] = fn
            }
        }
    </script>

</body>

</html>